<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改规则编排')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-flow-edit" th:object="${iotRuleFlow}">
            <input name="id" th:field="*{id}" type="hidden">

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">实例编码：</label>
                <div class="col-sm-8">
                    <input name="flowId" th:field="*{flowId}" class="form-control" required readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">实例名称：</label>
                <div class="col-sm-8">
                    <input name="flowName" th:field="*{flowName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">所属边缘网关：</label>
                <input type="hidden" id="edgeGatewayId" th:field="*{edgeGatewayId}">
                <div class="col-sm-8">
                    <select class="form-control" id="edgegateway2" name="edgeGatewayId">
                        <option value="">--请选择边缘网关--</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">说明：</label>
                <div class="col-sm-8">
                    <textarea name="detail" class="form-control">[[*{detail}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
            var ctx = [[@{/}]];
        var prefix = ctx + "system/flow";
        $("#form-flow-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-flow-edit').serialize());
            }
        }

        $("input[name='createdTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='updatedTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        getEdgeway();
        function getEdgeway(){
            $.ajax({
                type: "get",
                url: ctx + "system/gateway/all",
                success: function(data) {
                    console.log(data);
                    var htmlStr = ''
                    $.each(data.data, function(i,item){
                        var edgeGatewayId = $("#edgeGatewayId").val();
                        if(edgeGatewayId==item.id){
                            htmlStr += '<option value="'+item.id+'" selected>'+ item.name +'</option>'
                        }else{
                            htmlStr += '<option value="'+item.id+'">'+ item.name +'</option>'
                        }
                    });
                    $("#edgegateway2").html(htmlStr);
                }
            });
        }
    </script>
</body>
</html>